package engine.newUi
{
	import engine.control.loading.MultLoader;
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	import engine.event.BaseNetEvent;
	import engine.event.RoleEffectEvent;
	import engine.flag.Funcid;
	import engine.flag.ResourcesPath;
	import engine.logic.ActSee;
	import engine.logic.CustomLogic;
	import engine.logic.McPool;
	import engine.logic.SceneTransfer;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.scene.SceneClickLogic;
	import engine.scene.SceneManager;
	import engine.ui.MainUIManager;
	import engine.ui.lite.BaseUI;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.geom.Point;
	import flash.text.StyleSheet;
	import flash.text.TextField;
	
	import flashx.textLayout.container.ScrollPolicy;
	
	import mx.events.ResourceEvent;
	import mx.resources.ResourceBundle;
	import mx.resources.ResourceManager;
	
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.Scroll.NxScrollPanel;
	import newx.com.control.button.NxButton;
	import newx.com.control.text.NxText;
	import newx.utils.debug.IO;

	public class NpcTalkUI extends BaseUI
	{
		private static var _self	:NpcTalkUI
		
		private var model			:ModelLocator;
		
		public  var canShow		:Boolean	=	true;
		
		public var npcFace			:NxClip
		
		public var baseBG			:NxClip;
		
		public var npcTalkBack		:MovieClip;
		
		public var canshow			:Boolean = true ; 
		
//		public var msgTxt			:NxText;
		
		public var npcTalkTxt		:NxText;
		
		public var closeBtn		:NxButton;
		
		/**异步标示*/
		private var _mark			:Point;
		
		public var _curSelectObj	:Point;
		
		private var _linkPlace		:Sprite;
		
		public 	 var linkScroll		:NxScrollPanel;
		//============
		private var _npcFaceLeftX	:Number	=-1;
		private var _npcFaceRightX	:Number	=-1;
		private var _UILeftX		:Number	=-1;
		private var _UIRightX		:Number	=	-1;
		
		private var _isShow			:Boolean	=	false
		
		private var _taskInfoListArray	:Array;
		private var _taskOverArray		:Array;
		private var _taskArrayIndex	:int	=	0
		private var TaskType_Start			:String	=	"TaskStart";
		private var TaskType_Over			:String	=	"TaskOver";
		private var _menuListArray			:Array;
		private var _txtStyle	:StyleSheet	=	new StyleSheet();
		
		private var _taskIsOK:Boolean		=	false;
		
		private var _taskLogic			:TaskLogic
		
//		private var _infoTxtRightX	:Number	=	-1;
//		private var _infoTxtLeftX	:Number	=-	1;
		
		private var _place:Sprite;
		private var _isGetPerfectPosition	:Boolean=false;
		
		/**任务id号*/
		private 	var taskId		:int;
		//=============
		
		private var completeIndex:int	=	0;
		
		public static function getInstance():NpcTalkUI
		{
			if(_self == null)
			{
				_self	=	new NpcTalkUI();
				
			}
			return _self;
		}
		
		public function NpcTalkUI()
		{
			super(true);
		}
		override public function show(space:DisplayObjectContainer=null, onshow:Function=null, ...argc):void
		{
//			if(!MultLoader.getInstance().getSourceByUrl(ResPath.SWF +"NpcTalkUI" +".swf" ))
//			{
//				MultLoader.getInstance().load([ResPath.SWF +"NpcTalkUI" +".swf" ],false,createTaskUI);
//			}else
//			{
				createTaskUI();
//			}
		}
		private function createTaskUI():void
		{
//			baseBG.source=MultLoader.getInstance().getSourceByUrl(ResPath.SWF +"NpcTalkUI" +".swf" )
			baseBG.source = ResManager.newResClass ("CustomControl_036") as MovieClip ; 
			super.show();
		}
		override public function Init():void
		{			
			moveByScene = false;
			model	=	ModelLocator.getInstance();
			_taskLogic	=	new TaskLogic();
			model.addEventListener(BaseNetEvent.ADD_MENU,onAddMenu);
			model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_OPEN_TASK_ACCEPT_WINDOW), openTaskStart);
			model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_OPEN_TASK_COMPLETE_WINDOW),openTaskOver);
			
			//接取成功
			model.addEventListener( String( CustomToClientFlag.SERVER_CUSTOMMSG_TASK_ACCEPT_SUCCESS ), acceptTaskResult );
			//完成成功
			model.addEventListener( String( CustomToClientFlag.SERVER_CUSTOMMSG_TASK_COMPLETE_SUCCESS ), completeTaskResult );
			
			closeBtn.addEventListener(MouseEvent.CLICK,onCloseHandle);
			npcFace.isCache	=	true
			_linkPlace = new Sprite();
			addChild( _linkPlace );
			linkScroll.horizontalScrollPolicy 	= ScrollPolicy.OFF;
			linkScroll.verticalScrollPolicy 	= ScrollPolicy.AUTO;
			
			_txtStyle.setStyle("a:link"		,{color:"#"+StaticIni.getIniVar("Css_a_NpcTalk","link"),textDecoration:"underline"});
			_txtStyle.setStyle("a:visited"	,{color:"#"+StaticIni.getIniVar("Css_a_NpcTalk","visited")});
			_txtStyle.setStyle("a:hover"	,{color:"#"+StaticIni.getIniVar("Css_a_NpcTalk","hover"),textDecoration:"none"});
			_place		=	new Sprite();
			_place.x	=	npcTalkTxt.x;
			_place.y	=	npcTalkTxt.y;
			this.addChild(_place);
		}
		public function get effContiner():Sprite
		{
			return _place
		}
		
		private function acceptTaskResult( evt : CustomMsgEvent):void
		{
			var arrID:int	=	evt.pList[0];
			
			if(arrID == 4033) taskId	=	arrID;
			
			model.dispatchEvent( new RoleEffectEvent( RoleEffectEvent.ACCEPT_TASK ) );
			
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_TASK_CAN_ACCEPT);
			
			//收藏任务
			if(arrID == 4000){
				CustomLogic.getInstance().openFavorite();
				
				return;
			}

			if(evt.pList[1] != 16) autoGoWay();
		}
		
		private function completeTaskResult( evt : CustomMsgEvent):void
		{
			model.dispatchEvent( new RoleEffectEvent( RoleEffectEvent.COMPLETE_TASK) );
		}
		
		private function onCloseHandle(e:MouseEvent):void
		{
			doTextLink("60000");
		}
		override protected function BeforeShow():void
		{
			MainUIManager.getInstance().autoFoundWay	=	false;
			linkScroll.addView(_linkPlace);
			linkScroll.viewWidth = 300;
			linkScroll.vscroll = 0;
			_isShow	=	true;
//			linkScroll.autoScroll = true;
		}
		override protected function  AfterHide():void
		{
			_isShow	=	false;
			npcFace.clear();
		}
		/**
		 *  
		 * @param e
		 * 
		 */		
		private function clickHandle(e:MouseEvent):void
		{
			var str:String	=	"";
			var checkItem:MovieClip	=	e.currentTarget as MovieClip
			if(checkItem)
			{
				str	=	checkItem["data"];
			}
			IO.traceLog("str",str)
			
			if("60000"	==	str)
			{
				requestClose();
			}
			else if( "taskOver" == str)
			{
				nextOverTask();
				return;
			}
			else if( "taskStart" == str)
			{
				nextStartTask();
				return;
			}
			var	 funcId	:int	=	int(str);
			_taskIsOK	=	checkItem["isOK"];
			//领地宣战按钮
			if(funcId == 50117) ActSee.PostClientStatus(8302,1,1);
			
			//			hide()
			//			requestClose();
			//			npcFace.clear();
			//			if(funcId != Funcid.Funcid_CloseMenu)
			//			{
			SystemSender.getInstance().SelectMenu(_curSelectObj,_mark,funcId);
		}
		private function doTextLink(str:*):void					//点击NPC对话框文本中的“下一步”按钮;
		{
			if( str is TextEvent )
			{
				str = ( str as TextEvent ).text;
			}
			
			IO.traceLog("str",str)
			
			if("60000"	==	str)
			{
				requestClose();
			}
			else if( "taskOver" == str)
			{
				nextOverTask();
				return;
			}
			else if( "taskStart" == str)
			{
				nextStartTask();
				return;
			}
			
			var	 funcId	:int	=	int(str);
			
			//领地宣战按钮
			if(funcId == 50117) ActSee.PostClientStatus(8302,1,1);
			
//			hide()
//			requestClose();
//			npcFace.clear();
//			if(funcId != Funcid.Funcid_CloseMenu)
//			{
			SystemSender.getInstance().SelectMenu(_curSelectObj,_mark,funcId);
//			}
			
//			UIManage.getInstance().cancelCustUIMask();
		}
		
		private function showNpcFace():void
		{
			var npc				:Array 		=	model.scene.GetRecordEx("NpcStatusRec").recArr;
			
			npc.sortOn("1", Array.NUMERIC);
			
			for(var k:int = 0;k < npc.length;k++)
			{
				if(_curSelectObj.equals(npc[k][0]))
				{
					ResourcesPath.getHalfPic(npc[k][5],npcFace);
				}
			}
		}
		
		public function showTask( taskInfo : String, linkInfos : Array ):void
		{
			/*奇遇判断*/
			if(TipsWindowUI.getInstance().created==true )
			{
				return ; 
			}
			removeLinkMc();
			
			showNpcFace();
			
			npcTalkTxt.htmlText	=	"<font size='14'>"+taskInfo +"</font>";
			
			showLinks( [linkInfos], _txtStyle );
			
			if(!_isShow && canShow)
			{
				showOrHide()
			}
		}
		
		private function showNpcTalk( curSelectObj : Point, mark : Point, dataArr : Array ):void
		{
			completeIndex	=	0;
			
			removeLinkMc();
			
			showNpcFace();
			_taskIsOK	=	false;
			//			NpcIconManage.getInstance().addTalkNpc(_curSelectObj,this);
			var tSize1		:uint		=	dataArr.length;
			var tSize2		:uint;
			
			var type		:int;
			var funcID		:int;
			
			var str			:String;
			var pList		:Array;
			
			var tStr		:String		=	"";
			var npcTalkStr	:String		=	"";
			var txtStyle	:StyleSheet	=	new StyleSheet();
			
			
			var links : Array = [];
			
			for(var i:uint = 0 ; i < tSize1 ; i ++)
			{
				type	=	dataArr[i].GetProperties("nType");
				funcID	=	dataArr[i].GetProperties("nMark");
				str		=	dataArr[i].GetProperties("szInfo");
				pList	=	dataArr[i].GetProperties("argArr");
				
				tSize2	=	pList.length;
				
				for(var j:int = 0 ; j < tSize2 ; j ++)
				{
					if(String(pList[j]).charAt(0) != "_")
					{
						pList[j]	=	StaticIni.getSwfLangStr(pList[j]);
					}
					else
					{
						pList[j]	=	String(pList[j]).substring(1);
					}
				}
				
				var npcTalk : Object = StaticIni.getIniObj( "Css_a_NpcTalk" );
				
				switch(type)
				{
					//文本项
					case 0://size
						if(pList.length == 0){
							npcTalkStr+=StaticIni.getSwfLangStrVar("textcolor",
								["#"+npcTalk.default,StaticIni.getSwfLangStr(str)]);
						}else{
							npcTalkStr+=StaticIni.getSwfLangStrVar("textcolor",
								["#"+npcTalk.default,StaticIni.getSwfLangStrVar(str,pList)]);
						}
						npcTalkStr = StaticIni.getSwfLangStrVar( "textsize", [ npcTalk.size, npcTalkStr ] );
						npcTalkTxt.htmlText	=	npcTalkStr;
						break;
					//选择项<![CDATA[]]>
					case 2:
						var typeIndex:int = 0;
						if( str != "Task00007")
						{
							if(str == "Task00001")
							{
								typeIndex		=	2
								_taskIsOK	=	true;
							}
							else if(str == "Task00002")
							{
								typeIndex		=	1
								_taskIsOK	=	false;
							}
							else if(str == "Task00003")
							{
								_menuListArray.push("have one menu, can agaic click");
								typeIndex		=	0
								_taskIsOK	=	false;
							}
							else if( str == "SpringTalk_8008")
							{
								typeIndex		=	3
								_taskIsOK	=	true;
							}
							
							if(_taskIsOK) completeIndex++;
							links.push( ["<a href='event:"+funcID+"'>"+StaticIni.getSwfLangStrVar(str,pList)+"</a>", funcID,_taskIsOK,typeIndex]);
						}		
						break;
					//物品显示
					case 3:
						break;
					//					MENU_CLOSE	 = 4,	//关闭按钮
					case 4:
						closeBtn.visible=false;
						break;
					//						MENU_POS	 = 5,	//位置
					case 5:
						break;
				}
			}
			links.sort(linkArray);
			showLinks( links, _txtStyle );
			if(!_isShow)
			{
				showOrHide();
			}
			//UIManage.getInstance().setCustUIMask(this.parent)
			//	this.parent.setChildIndex(this,this.parent.numChildren-1);
			//setPosition(leftOrRight);
		}
		/**
		 * 排序 
		 * @param item
		 * @return 
		 * 
		 */		
		private function linkArray(item1:Array,item2:Array):int
		{
			var star1:int	=	item1[3] as int;
			var star2:int	=	item2[3] as int;
			var a:Boolean	=	item1[2] as Boolean
			var b:Boolean	=	item2[2] as Boolean
			var checkIng:int		=	0;

			if(a&&b)
			{
				checkIng = 0;
			}
			else 
			{
				if(b)
				{
					checkIng = 1;
				}
				else if(a)
				{
					checkIng = -1;
				}
				else if(!a && !b)
				{
					
					checkIng =  star1 - star2;
					if(checkIng > 0)
					{
						checkIng	= 1
					}
					else if(checkIng < 0)
					{
						checkIng = -1
					}
					else
					{
						checkIng = 0
					}
				}
			}
			return checkIng;
		}
		private function onAddMenu(e:BaseNetEvent):void
		{
			closeBtn.visible=true;//按钮默认显示
			var leftOrRight:String="right";
			_menuListArray					=	[];
			_curSelectObj					= 	e.data[0];			
			_mark							= 	e.data[1];
			showNpcTalk( _curSelectObj, _mark, e.data[2] )
		}
		
		private function showLinks( links : Array, txtStyle : StyleSheet ):void
		{
			var mc : MovieClip;//custSkin_0007
			var txt : TextField;
			for( var i : int = 0; i < links.length; i++ )
			{
				mc = getLinkMc( txtStyle );
				( mc.infoTxt as TextField ).htmlText	= 	links[ i ][0];
				mc.y									= 	17 * i;
				mc["data"]								=	links[ i ][1];
				mc["isOK"]								=	links[ i ][2];
				_linkPlace.addChild( mc );
			}
			linkScroll.upDataScrollPanel(1);
			linkScroll.vscroll	=	0;
		}
		
		private function getLinkMc( txtStyle : StyleSheet ):MovieClip
		{
			var mc : MovieClip = McPool.borrowRes( "custSkin_0007" );
			mc.mouseChildren = true;
			( mc.infoTxt as TextField ).styleSheet	=	txtStyle;
			if(!mc.hasEventListener(MouseEvent.CLICK))
			{
				mc.buttonMode	=	true;
				mc.addEventListener(MouseEvent.CLICK,clickHandle);
			}
//			if( ! ( mc.infoTxt as TextField ).hasEventListener( TextEvent.LINK ) )
//			{
//				( mc.infoTxt as TextField ).addEventListener( TextEvent.LINK, doTextLink );
//			}
			return mc;
		}
		
		private function removeLinkMc():void
		{
			var mc : MovieClip;
			while( _linkPlace.numChildren > 0 )
			{
				mc = _linkPlace.removeChildAt( 0 ) as MovieClip;
				
				McPool.returnRes( "custSkin_007", mc );
			}
		}
		
		private function setPosition(type:String):void
		{
			if(!_isGetPerfectPosition)
			{
				_isGetPerfectPosition=true;
				_UIRightX=this.x;
				_npcFaceRightX=this.npcFace.x;
//				_infoTxtRightX=this.msgTxt.x;
				
//				var offsetX:Number=StageInfo.rootW-this.x-this.msgTxt.x-this.msgTxt.width;
//				_npcFaceLeftX=	180;//-offsetX-(this.msgTxt.x+this.msgTxt.width-this.npcFace.x);
//				_UILeftX	 =	-180;//offsetX-this.msgTxt.x;
//				_infoTxtLeftX	=
			}
			
			
			if("left"	==	type)
			{
				this.x=_UILeftX;
				this.npcFace.x=_npcFaceLeftX;
//				this.msgTxt.x	=_infoTxtLeftX;
			}
			else if("right"	==	type)
			{
				this.x=_UIRightX;
				this.npcFace.x=_npcFaceRightX;
//				this.msgTxt.x=	_infoTxtRightX;
			}
		}

		/**打开一个任务承接确认窗口*/
		public function openTaskStart(e:CustomMsgEvent):void
		{
			MainUIManager.getInstance().autoFoundWay	=	false;
			//clearTaskInfo();
			//e.pList[1] 标示是否可以取消任务接收 0 ：可以，1：不可以
			taskId	=	e.pList[0];
			
			getTaskInfo( taskId);
		}
		
		//完成任务
		public function openTaskOver(e:CustomMsgEvent=null, mulNum:Number=1):void
		{
			taskId	=	e.pList[0];
			
			MainUIManager.getInstance().autoFoundWay	=	false;
			
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_GET_DAILY_TASK_PRIZE, taskId);
			
			taskOverInfo( taskId);
		}
		
		private function getTaskInfo( taskId :int):void
		{
			_taskInfoListArray			=	[]
			_taskArrayIndex				=	0;
			// 任务描述
			var taskContext:String	=	StaticIni.getSwfLangStr("Task_Context" + taskId);
			// 接取NPC
			var acceptNPC:String	=	""//StaticIni.getSwfLangStr("Task_AcceptNpc" + taskId);
			// 提交NPC
			var submitNPC:String	=	""//StaticIni.getSwfLangStr("Task_SubmitNpc" + taskId);
			// 任务要求
			var taskSummar:String	=	StaticIni.getSwfLangStr("Task_Summar" + taskId);
			// 任务进度
			var schedule:String 	= 	"";
			// 奖励金币
			var prizeMoney:int 		= 	int(StaticIni.getIniVar("taskprize_"+taskId,"money"));
			//绑定金币
			var boundMoney:int		=	int(StaticIni.getIniVar("taskprize_"+taskId,"boundmoney"));
			// 奖励精力
			var prizeExp:int		= 	int(StaticIni.getIniVar("taskprize_"+taskId,"exp"));
			//奖励功勋
			var peerexp	:int		=	int(StaticIni.getIniVar("taskprize_"+taskId,"peerexp"));
			// 扩展描述
			var addInfo1	:String	=	StaticIni.getIniVar("taskprize_"+taskId,"addInfo1");
			
			//城堡任务奖励
			var castlePoint:int = int(StaticIni.getIniVar("taskprize_"+taskId,"castlePoint"));
			//食物资源
			var castleResource_Farm:int = int(StaticIni.getIniVar("taskprize_"+taskId,"castleResource_Farm"));
			//军事训练值
			var castleResource_Stone:int = int(StaticIni.getIniVar("taskprize_"+taskId,"castleResource_Stone"));
			//石料资源
			var castleResource_Knight:int = int(StaticIni.getIniVar("taskprize_"+taskId,"castleResource_Knight"));
			//技术研究值
			var castleResource_Tech:int = int(StaticIni.getIniVar("taskprize_"+taskId,"castleResource_Tech"));
			var npcTalk : Object = StaticIni.getIniObj( "Css_a_NpcTalk" );
			taskContext = StaticIni.getSwfLangStrVar( "textsize", [ npcTalk.size, taskContext ] );
			//	taskSummar = StaticIni.getSwfLangStrVar( "textsize", [ npcTalk.size, taskSummar ] );
			var infoHtml : String			=	StaticIni.getSwfLangStrVar("Task_Info_TaskUI_1",			
				[taskContext,    schedule,
					prizeMoney, prizeExp]);
			var info:String = "";
			info +=  	StaticIni.getSwfLangStrVar("Task_Info_TaskUI_4",[taskSummar]);
			if(prizeMoney>0)
			{
				info		+=	StaticIni.getSwfLangStrVar("Task_prizeMagicCoin_1",[prizeMoney]);
			}
			if(boundMoney>0)
			{
				info		+=	StaticIni.getSwfLangStrVar("Task_prizeCoin_1",[boundMoney]);
			}
			if(prizeExp>0)
			{
				info		+=	StaticIni.getSwfLangStrVar("Task_prizeExp_1",[prizeExp]);
			}
			if(castlePoint > 0)
			{
				info		+=	StaticIni.getSwfLangStrVar("Task_prizeCastlePoint_1",[castlePoint]);
			}
			if(peerexp > 0)
			{
				info		+=	StaticIni.getSwfLangStrVar("Task_prizeExploit_1",[peerexp]);
			}
			if(castleResource_Farm > 0)
			{
				info		+=	StaticIni.getSwfLangStrVar("Task_prizeCastleResource_Farm_1",[castleResource_Farm]);
			}
			if(castleResource_Stone > 0)
			{
				info		+=	StaticIni.getSwfLangStrVar("Task_prizeCastleResource_Stone_1",[castleResource_Stone]);
			}
			if(castleResource_Knight > 0)
			{
				info		+=	StaticIni.getSwfLangStrVar("Task_prizeCastleResource_Knight_1",[castleResource_Knight]);
			}
			if(castleResource_Tech > 0)
			{
				info		+=	StaticIni.getSwfLangStrVar("Task_prizeCastleResource_Tech_1",[castleResource_Tech]);
			}
			
			if(addInfo1.length>0)
				
			{
				infoHtml		+=	StaticIni.getSwfLangStr(addInfo1);
			}
			
			_taskInfoListArray.push([infoHtml,["<a href='event:taskStart'>" +StaticIni.getSwfLangStr("好的,我马上就去！") + "</a>","taskStart"]]);
			_taskInfoListArray.push([info,["<a href='event:taskStart'>" +StaticIni.getSwfLangStr("接受任务") + "</a>","taskStart"]]);
			nextStartTask()
			
			linkScroll.vscroll = 0;
		}
		/**
		 *  以接取过的和完成了的
		 */		
		private function taskOverInfo(taskID:int):void
		{
			_taskInfoListArray	=	[];
			//判断是否为主线
			_taskArrayIndex		=	0;
			if(_taskIsOK)
			{
				_taskInfoListArray.push([StaticIni.getSwfLangStr("Task_Completed" + taskID),["<a href='event:taskOver'>" +StaticIni.getSwfLangStr("提交任务") + "</a>","taskOver"]]);
				
			}
			else
			{
				_taskInfoListArray.push(["你怎么还没有去！",["<a href='event:taskOver'>" +StaticIni.getSwfLangStr("我这就去！") + "</a>","taskOver"]]);
				
			}
			
			nextOverTask();
			
			linkScroll.vscroll = 0;
		}
		/**
		 * 接取任务文本显示顺序 
		 */		
		private function nextStartTask():void
		{
			if(_taskArrayIndex < _taskInfoListArray.length)
			{
				showTask( _taskInfoListArray[_taskArrayIndex][0], _taskInfoListArray[_taskArrayIndex][1] );
				_taskArrayIndex++;
			}
			else
			{
				getTask();
				
			}
			
		}
		
		/**
		 * 完成任务文本显示顺序 
		 */	
		private function nextOverTask():void
		{
			if(_taskArrayIndex < _taskInfoListArray.length)
			{
				showTask( _taskInfoListArray[_taskArrayIndex][0], _taskInfoListArray[_taskArrayIndex][1] );
				_taskArrayIndex++;
			}
			else if(completeIndex >1)
			{
				onOverTask();
				if(SceneClickLogic.currentNPC) SystemSender.getInstance().SelectObjInScene(SceneClickLogic.currentNPC.playerObj.ObjID, Funcid.Funcid_BeginMenu);
			}
			else
			{
				onOverTask();
				this.showOrHide();
			}
		}
		/**
		 *任务完成
		 * @param e
		 * 
		 */		
		private function onOverTask():void
		{		
			completeIndex--;
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_TASK_CONFIRM_COMPLETE, 0, taskId);
//			autoGoWay();
			if(!_taskIsOK)
			{
				//收藏任务
				if(taskId == 4000){
					CustomLogic.getInstance().openFavorite();
					
					return;
				}
				autoGoWay();
			}
//			requestClose();
		}
		
		private function getTask():void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_TASK_CONFIRM_ACCEPT,taskId);
			requestClose();
		}
		private function autoGoWay():void
		{
			if(FunctionGuideUI.getInstance().stage) return;
			var taskLink:String	=	"";
			if(taskId < 4000 || String(taskId).slice(0,1) == "8" || taskId == 4033)
			{
				taskLink	=	_taskLogic.getTaskLinkID(taskId);
				if(taskLink != "")
				{
					SceneTransfer.getInstance().tranferTo( taskLink );
					SceneManager.getInstance()._sceneClickLogic.clearClickNpc();
				}
			}
			else 
			{
				if(_menuListArray.length > 1)
				{
					SceneManager.getInstance()._sceneClickLogic.agaicClickNpc();
				}
				else
				{
					SceneManager.getInstance()._sceneClickLogic.clearClickNpc();
				}
			}

		}
	}
}